package com.suzus.medicineGraph.dao;

import com.suzus.medicineGraph.model.Medicine;
import org.neo4j.driver.internal.value.PathValue;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface MedicineRepository extends Neo4jRepository<Medicine,Long> {

    @Query("MATCH (n:Medicine {name: $from}), (m:Symptom {name: $to}) CREATE (n)-[:治疗]->(m)")
    void createRelation(@Param("from") String from, @Param("to") String to);

    @Query("MATCH p=()-[:治疗]->() RETURN p LIMIT 100")
    ArrayList<PathValue> queryRelation();

    @Query("MATCH p = ({name: $from})-[]->() return p")
    ArrayList<PathValue> queryMedicineRelation(@Param("from") String from);

    @Query("MATCH (p:Medicine {name: $from}) return p")
    Medicine queryMedicine(@Param("from") String from);

}
